package richtext


type Block struct {
	ClassList  [] string
	Lines      [] Line
	Children   [] Block
}
func (b *Block) AddClass(classes ...string) {
	b.ClassList = append(b.ClassList, classes...)
}
func (b *Block) WriteLine(content string, tags ...string) {
	b.Lines = append(b.Lines, Line { [] Span { {
		Content: content,
		Tags:    tags,
	} } })
}
func (b *Block) WriteSpan(content string, tags ...string) {
	var span = Span {
		Content: content,
		Tags:    tags,
	}
	if len(b.Lines) > 0 {
		var last = &(b.Lines[len(b.Lines) - 1])
		last.Spans = append(last.Spans, span)
	} else {
		b.Lines = append(b.Lines, Line { Spans: [] Span { span } })
	}
}
func (b *Block) WriteLineFeed() {
	b.Lines = append(b.Lines, Line { Spans: [] Span {} })
}
func (b *Block) Append(another Block) {
	b.Children = append(b.Children, another)
}

type Line struct {
	Spans  [] Span
}

type Span struct {
	Content  string
	Tags     [] string
	Link     MaybeLink
}
const (
	TAG_DOC          = "doc"
	TAG_EM           = "em"
	TAG_SRC_NORMAL   = "source"
	TAG_SRC_KEYWORD  = "keyword"
	TAG_SRC_NAME     = "name"
	TAG_SRC_TYPE     = "type"
	TAG_SRC_FUNCTION = "function"
	TAG_SRC_CONST    = "const"
	TAG_SRC_COMMENT  = "comment"
	TAG_HIGHLIGHT    = "highlight"
	TAG_ERR_NORMAL   = "error"
	TAG_ERR_NOTE     = "note"
	TAG_ERR_INLINE   = "inline"
)

type MaybeLink interface { Maybe(Link, MaybeLink) }
func (Link) Maybe(Link, MaybeLink) {}
type Link struct {
	Page    string
	Anchor  string
}


